// Upgrade NOTE: commented out 'float4 unity_LightmapST', a built-in variable
// Upgrade NOTE: commented out 'float4x4 _Object2World', a built-in variable
// Upgrade NOTE: commented out 'sampler2D unity_Lightmap', a built-in variable
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
// Upgrade NOTE: replaced tex2D unity_Lightmap with UNITY_SAMPLE_TEX2D


Shader  "Custom/InterpolatedLightsAOBlendColour" {

    Properties
    {
_MainTex("Texture 1", 2D) = "white" {}
_LightColour0("Light colour 0", Color) = (1,0.73,0.117,0)
_LightColour1("Light colour 1", Color) = (0.05,0.275,0.275,0)
_LightColour2("Light colour 2", Color) = (0,0,0,0)
_LightColour3("Rim colour", Color) = (0,0,0,0)
_LightTint("Light Multiplier", Color) = (1,1,1,0)
_AmbientColour1("Light Add", Color) = (0.5,0.5,0.5,0)
_ShadowColour("Shadow Tint", Color) = (0,0,0,0)
_ShadowRamp("ShadowBoost", Float) = 1
_UseLightMap("Debug Mode", Float) = 1
_BlendColor("_BlendColor", Color) = (1,0,0,1)
_Blend("_Blend", Float) = 1
    }



        SubShader
{
Tags { "LIGHTMODE" = "ForwardBase" "QUEUE" = "Geometry" "RenderType" = "Opaque" }

  LOD 100
  Pass
  {



  CGPROGRAM
  #pragma vertex vert
  #pragma fragment frag
  #include "UnityCG.cginc"
  #define Fixed3(value)  fixed3(value, value,value)

  struct VertexInput {
  fixed4 vertex : POSITION;
  fixed2 xlv_TEXCOORD0 : TEXCOORD0;
  fixed2 xlv_TEXCOORD1 : TEXCOORD1;
  //fixed3 xlv_TEXCOORD2 : TEXCOORD2;
  //fixed3 xlv_TEXCOORD3 : TEXCOORD3;
  //fixed4 tangent : TANGENT;
  fixed3 normal : NORMAL;
  //fixed4 xlv_COLOR : COLOR;
  //VertexInput
  };


  struct VertexOutput {
  fixed4 pos : SV_POSITION;
  UNITY_FOG_COORDS(1)
      //fixed4 xlv_COLOR : COLOR;
      fixed2 xlv_TEXCOORD0 : TEXCOORD0;
      fixed2 xlv_TEXCOORD1 : TEXCOORD1;
      fixed3 xlv_TEXCOORD2 : TEXCOORD2;
      //fixed3 xlv_TEXCOORD3 : TEXCOORD3;
      //fixed3 xlv_TEXCOORD4 : TEXCOORD4;
      //VertexOutput
      };



  // float4x4 _Object2World;
  // float4 unity_LightmapST;
  float4 _MainTex_ST;
  float4 _LightColour0;
  float4 _LightColour1;
  float4 _LightColour2;
  float4 _LightColour3;
  float4 _AmbientColour1;




  // sampler2D unity_Lightmap;
  sampler2D _MainTex;
  float _ShadowRamp;
  float4 _ShadowColour;
  float4 _LightTint;
  float _UseLightMap;
  float4 _BlendColor;
  float _Blend;
  ;
  ;
  ;




     VertexOutput vert(VertexInput v)
     {
     VertexOutput o;
     //o.pos = UnityObjectToClipPos (v.vertex);
     //o.xlv_TEXCOORD0 = TRANSFORM_TEX(v.xlv_TEXCOORD0, _MainTex);

   float3 darkSide3_1;
   float3 darkSide1_2;
   float3 flatWorldNormal_3;
   float4 tmpvar_4;
   tmpvar_4 = UnityObjectToClipPos(v.vertex);
   float2 tmpvar_5;
   tmpvar_5 = ((v.xlv_TEXCOORD0 * _MainTex_ST.xy) + _MainTex_ST.zw);
   float2 tmpvar_6;
   tmpvar_6 = ((v.xlv_TEXCOORD1.xy * unity_LightmapST.xy) + unity_LightmapST.zw);
   float4 tmpvar_7;
   tmpvar_7.w = 0.0;
   tmpvar_7.xyz = normalize(v.normal);
   float3 tmpvar_8;
   tmpvar_8 = normalize(mul(unity_ObjectToWorld , tmpvar_7).xyz);
   flatWorldNormal_3.xy = tmpvar_8.xy;
   flatWorldNormal_3.z = 0.0;
   float tmpvar_9;
   tmpvar_9 = sqrt(dot(flatWorldNormal_3, flatWorldNormal_3));
   if ((tmpvar_9 > 0.0001)) {
     flatWorldNormal_3 = normalize(flatWorldNormal_3);
   };
   float tmpvar_10;
   tmpvar_10 = clamp(-(flatWorldNormal_3).x, -1.0, 1.0);
   float tmpvar_11;
   tmpvar_11 = ((1.5708 - (
     sign(tmpvar_10)
    *
     (1.5708 - (sqrt((1.0 -
       abs(tmpvar_10)
     )) * (1.5708 + (
       abs(tmpvar_10)
      *
       (-0.214602 + (abs(tmpvar_10) * (0.0865667 + (
         abs(tmpvar_10)
        * -0.0310296))))
     ))))
   )) / 1.5708);
   darkSide1_2 = _LightColour3.xyz;
   darkSide3_1 = _LightColour3.xyz;
   if ((_UseLightMap < 0.5)) {
     darkSide1_2 = fixed3(0.5, 0.5, 0.5);
     darkSide3_1 = fixed3(0.75, 0.75, 0.75);
   };
   float tmpvar_12;
   tmpvar_12 = clamp(-(tmpvar_8).z, -1.0, 1.0);
   float tmpvar_13;
   tmpvar_13 = (1.0 - ((1.5708 -
     (sign(tmpvar_12) * (1.5708 - (sqrt(
       (1.0 - abs(tmpvar_12))
     ) * (1.5708 +
       (abs(tmpvar_12) * (-0.214602 + (abs(tmpvar_12) * (0.0865667 +
         (abs(tmpvar_12) * -0.0310296)
       ))))
     ))))
   ) / 1.5708));
   o.pos = tmpvar_4;
   o.xlv_TEXCOORD0 = tmpvar_5;
   o.xlv_TEXCOORD1 = tmpvar_6;
   o.xlv_TEXCOORD2 = (lerp(lerp(
     lerp(_LightColour0.xyz, darkSide1_2, Fixed3(fixed((flatWorldNormal_3.x >= 0.0))))
   ,
     lerp(_LightColour1.xyz, darkSide1_2, Fixed3(fixed((0.0 >= flatWorldNormal_3.y))))
   , Fixed3(
     lerp(tmpvar_11, (2.0 - tmpvar_11), fixed((flatWorldNormal_3.x >= 0.0)))
   )), lerp(_LightColour2.xyz, darkSide3_1, Fixed3(
     fixed((0.0 >= -(tmpvar_8.z)))
   )), Fixed3(lerp(tmpvar_13,
     -(tmpvar_13)
   ,
     fixed((0.0 >= tmpvar_13))
   ))) + _AmbientColour1.xyz);


     UNITY_TRANSFER_FOG(o,o.vertex);

     return o;
     }


     fixed4 frag(VertexOutput i) : SV_Target
     {
         //fixed4 tmpvar_2 = tex2D(_MainTex, i.uv);
         UNITY_APPLY_FOG(i.fogCoord, tmpvar_2);

       half4 blend_color_1;
       float4 tex_2;
       float ShadowValue_3;
       half4 main_color_4;
       main_color_4 = fixed4(0.0, 0.0, 0.0, 0.0);
       fixed3 tmpvar_5;
       tmpvar_5 = (2.0 * UNITY_SAMPLE_TEX2D(unity_Lightmap, i.xlv_TEXCOORD1).xyz);
       ShadowValue_3 = clamp((_ShadowRamp * (1.0 - tmpvar_5)).x, 0.001, 0.999);
       if ((_UseLightMap < 0.5)) {
         ShadowValue_3 = 0.0;
       };
       fixed4 tmpvar_6;
       tmpvar_6 = tex2D(_MainTex, i.xlv_TEXCOORD0);
       tex_2 = tmpvar_6;
       float3 tmpvar_7;
       tmpvar_7 = lerp(((_LightTint.xyz * i.xlv_TEXCOORD2) * tex_2.xyz), _ShadowColour.xyz, fixed3(ShadowValue_3,ShadowValue_3,ShadowValue_3));
       main_color_4.xyz = tmpvar_7;
       main_color_4.w = 1.0;
       float4 tmpvar_8;
       tmpvar_8 = (tex_2 * _BlendColor);
       blend_color_1.xyz = tmpvar_8.xyz;
       blend_color_1.w = 1.0;
       float4 tmpvar_9;
       tmpvar_9 = lerp(blend_color_1, main_color_4, fixed4(_Blend,_Blend,_Blend,_Blend));
       main_color_4 = tmpvar_9;
        return main_color_4;
         }
         ENDCG
         }
}
Fallback "Diffuse"
}

